
export const getCookie = (key) => {
  let c_start,c_end
  if(document.cookie.length>0){
    c_start=document.cookie.indexOf(key+'=')
    if (c_start!==-1) {
      c_start=c_start+key.length+1
      c_end=document.cookie.indexOf(';',c_start)
      if(c_end===-1){
        c_end=document.cookie.length
      }
      return unescape(document.cookie.substring(c_start,c_end))
    }
  }
  return null
}

export const setCookie = (key,value,expiredays) => {
  var exdate=new Date()
  exdate.setDate(exdate.getDate()+expiredays)
  document.cookie=key+ "=" +escape(value)+
  ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

export const downloadFile = (src,src2) => {
    var a = document.createElement('a');
    a.setAttribute("href", src);
    a.setAttribute("download",src+'.'+src2);
    var evObj = document.createEvent('MouseEvents');
    evObj.initMouseEvent( 'click', true, true, window, 0, 0, 0, 0, 0, false, false, true, false, 0, null);
    a.dispatchEvent(evObj);
}
